package com.geek.busness.handler;

import com.geek.busness.config.ConfigLoader;
import com.geek.busness.continuous.MouseContinuous;
import com.geek.busness.view.Config;
import com.geek.monitor.event.HookEvent;
import com.geek.monitor.event.HookMouseEvent;
import com.geek.monitor.handler.MouseEventHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * 业务鼠标监听处理器
 */
@Slf4j
public class MyMouseEventHandler extends MouseEventHandler {

	private MouseContinuous mouseContinuous = new MouseContinuous();

	private boolean isStarted = false;

	private Config config;
	public MyMouseEventHandler(){
		this.config = ConfigLoader.load();
	}

	@Override
	public void handle(HookEvent event) {
		switch (event.getCode()) {
			case HookMouseEvent.MOUSEDOWN: {
				if(!isStarted){
					log.debug("USER MOUSEDOWN");
					if(this.config.isStarted()){
						mouseContinuous.start();
						isStarted = true;
					}
				}
				break;
			}
			case HookMouseEvent.MOUSEUP: {
				log.debug("USER MOUSEUP");
				if(isStarted){
					mouseContinuous.stop();
					isStarted = false;
				}
				break;
			}
		}

	}

}
